package com.ants.boot.system.service.impl;

import com.ants.boot.model.BaseModel;
import com.ants.boot.system.dao.OperateLogMapper;
import com.ants.boot.system.domain.OperateLog;
import com.ants.boot.system.dto.operatelog.QueryOperateLogDto;
import com.ants.boot.system.service.OperateLogService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author 蚂蚁会花呗
 * @date 2022/1/11 17:13
 */
@Service
public class OperateLogServiceImpl extends ServiceImpl<OperateLogMapper, OperateLog> implements OperateLogService {
    @Override
    public IPage<OperateLog> pageInfo(QueryOperateLogDto dto) {
        QueryWrapper<OperateLog> queryWrapper = new QueryWrapper<>();
        Page<OperateLog> page = new Page<>(dto.getPageNum(),dto.getPageSize());
        if (StringUtils.isNotBlank(dto.getModule())){
            queryWrapper.lambda()
                    .like(OperateLog::getModule,dto.getModule());
        }
        if (StringUtils.isNotBlank(dto.getOperatePerson())){
            queryWrapper.and(wrapper->wrapper.lambda().like(OperateLog::getOperatePerson,dto.getOperatePerson()));
        }
        if (StringUtils.isNotBlank(dto.getStartTime()) && StringUtils.isNotBlank(dto.getEndTime())){
            queryWrapper.and(wrapper->wrapper.lambda().between(OperateLog::getCreateTime,dto.getStartTime(),dto.getEndTime()));
        }
        queryWrapper.lambda().orderByDesc(OperateLog::getCreateTime);
        return this.page(page,queryWrapper);
    }

    @Override
    @Transactional
    public boolean delLog(List<Integer> ids) {
        return this.removeByIds(ids);
    }
}
